package com.turnengine.client.local.turn.command;

import com.javabi.command.IExecutableCommand;
import com.javabi.command.IExecutableCommandResponse;
import com.javabi.command.serializer.AbstractCommandDataSerializer;
import com.javabi.common.io.data.IDataReader;
import com.javabi.common.io.data.IDataWriter;
import com.turnengine.client.local.turn.enums.TurnUpdating;
import java.io.IOException;

/**
 * The Get Turn Updating Data Serializer.
 */
public class GetTurnUpdatingDataSerializer extends AbstractCommandDataSerializer<TurnUpdating> implements IGetTurnUpdatingDataSerializer {

	/**
	 * Creates a new Get Turn Updating Data Serializer.
	 */
	public GetTurnUpdatingDataSerializer() {
		super(GetTurnUpdating.COMMAND_ID);
	}

	@Override
	public TurnUpdating readReturnValue(IDataReader reader) throws IOException {
		TurnUpdating value = reader.readEnum(TurnUpdating.class, true);
		return value;
	}

	@Override
	public void writeReturnValue(IDataWriter writer, TurnUpdating value) throws IOException {
		writer.writeEnum(value, true);
	}

	@Override
	public IExecutableCommand<TurnUpdating> readRequest(IDataReader reader) throws IOException {

		// Read fields
		long loginId = reader.readLong();
		int instanceId = reader.readInt();

		// Create object
		GetTurnUpdating object = new GetTurnUpdating();
		object.setLoginId(loginId);
		object.setInstanceId(instanceId);
		return object;
	}

	@Override
	public void writeRequest(IDataWriter writer, IExecutableCommand<TurnUpdating> argument) throws IOException {
		GetTurnUpdating object = (GetTurnUpdating) argument;

		// Get fields
		long loginId = object.getLoginId();
		int instanceId = object.getInstanceId();

		// Write fields
		writer.writeLong(loginId);
		writer.writeInt(instanceId);
	}

	@Override
	public IExecutableCommandResponse<TurnUpdating> newResponse() {
		return new GetTurnUpdatingResponse();
	}
}
